<?php
/**
 * Created by PhpStorm.
 * User: teddy
 * Date: 5/27/16
 * Time: 3:49 PM
 */

$JobID = $_GET['jobid'];

/*数据库链接*/
$mysqli = new mysqli('192.168.2.191','root','pwd','APITEST');

/*Sql语句*/
$sql = "SELECT label,sum(latency) as latency, AVG(latency) as average FROM APITEST.TestResult where label in (SELECT label FROM APITEST.TestResult where jobid = " . $JobID . " ) group by label order by average desc ";

/*设置UTF8*/
$mysqli->query("set character set 'utf8'");
$mysqli->query("set names 'utf8'");

/*取数据*/
$results = $mysqli->query($sql);

$resultOutput = "";

/*把数据放在Array中*/
while($row = $results->fetch_assoc())
{

    $resultOutput = $resultOutput . $row['label'] . "\t" . $row['average'] . "\n";
}

$resultOutput = rtrim($resultOutput, "\n");
echo $resultOutput;

/*释放资源*/
$results->free();

/*关闭链接*/
$mysqli->close();